package neuralmusic.brain.module;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Random;

import javax.swing.Timer;

import uk.co.drpj.util.tweaks.TweakableDouble;

public class RandomExcitor {
	
	Timer timer;
	public RandomExcitor(Module module,final int nMax,final Random rand,final TweakableDouble amount) {
		
		final List<Neuron>  nn = module.getNeurons();
		final int nNeuron=nn.size();
		
		timer=new Timer(10,new ActionListener(){
	
			@Override
			public void actionPerformed(ActionEvent e) {
				double a=amount.doubleValue();
				int n=rand.nextInt(nMax);
				for (int i=0;i<n;i++){
					int in=rand.nextInt(nNeuron);
					nn.get(in).excite((float) a);
					//System.out.println(" Noise "+a);
				}
			}
			
		});
		
		
	}
	
	public void start(){
		timer.start();
	}

}
